<template>
	<view class="center">
	</view>
</template>

<script>
	import service_player from '@/service/player.js';
	export default {
		data() {
			return {
				user_id: uni.getStorageSync('userId'),
				id: '',
				back: false,
			}
		},
		onLoad(options) {
			this.id = options.id;
			console.log(this.id, 'onLoad')
			let token = uni.getStorageSync('token')
			uni.setStorageSync('roomId', options.id)
			if (token == '' || token == null) {
				uni.setStorageSync('Router', 'pages/livePlayer/index/index?id=' + options.id)
				uni.redirectTo({
					url: '/pages_login/pages/login/login/index'
				});
			} else {
				this.xcxLivePlayer(options.id);
			}
		},
		onShow() {
			if (this.back === true) {
				console.log(this.back, '返回')
				this.back = false;
				uni.switchTab({
					url: '/pages/home/index/index'
				});
				return false;
			} else {
				let token = uni.getStorageSync('token')
				let room_id = uni.getStorageSync('roomId')
				if (token != '' && room_id != '') {
					this.xcxLivePlayer(room_id);
				}
			}
		},
		methods: {
			//直播分享
			xcxLivePlayer(ids) {
				//小程序进直播间
				var roomId = [ids] // 房间号
				// let custom_params={
				// 	userId:this.user_id
				// }
				// var customParams = encodeURIComponent(JSON.stringify({custom_params}))
				var _this = this;
				setTimeout(function() {
					_this.back = true;
				}, 1500);
				let share_uid = uni.getStorageSync('liveShare');
				if (share_uid > 0 && share_uid != '') {
					let params = {
						invit_user_id: share_uid,
						roomid: ids
					};
					service_player.xcxLiveShare(params).then(res => {
						uni.removeStorageSync('liveShare');
						uni.removeStorageSync('roomId');
						uni.navigateTo({
							url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${_this.user_id}&open_share_ticket=1`
						});
					})
				} else {
					uni.removeStorageSync('roomId');
					uni.navigateTo({
						url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${_this.user_id}&open_share_ticket=1`
					});
				}
			}
		},
	}
</script>

<style>
</style>
